package com.sangfor.ssl.common;

import android.content.Context;
import android.net.wifi.WifiManager;
import android.text.TextUtils;
import com.sangfor.bugreport.logger.Log;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

/* loaded from: classes2.dex */
public class DeviceInfo {
    private static final String DEFAULT_MAC_ADDRESS = "02:00:00:00:00:00";

    public static String getWifiMac(Context context) {
        if (context == null) {
            return DEFAULT_MAC_ADDRESS;
        }
        String macAddress = ((WifiManager) context.getSystemService("wifi")).getConnectionInfo().getMacAddress();
        if (TextUtils.isEmpty(macAddress) || TextUtils.equals(macAddress, DEFAULT_MAC_ADDRESS)) {
            macAddress = getLocalMacAddressFromIp();
        }
        return TextUtils.isEmpty(macAddress) ? DEFAULT_MAC_ADDRESS : macAddress;
    }

    private static String getLocalIpAddress() {
        try {
            Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
            while (networkInterfaces.hasMoreElements()) {
                Enumeration<InetAddress> inetAddresses = networkInterfaces.nextElement().getInetAddresses();
                while (inetAddresses.hasMoreElements()) {
                    InetAddress nextElement = inetAddresses.nextElement();
                    if (!nextElement.isLoopbackAddress() && !nextElement.isLinkLocalAddress()) {
                        return nextElement.getHostAddress().toString();
                    }
                }
            }
            return null;
        } catch (SocketException e) {
            Log.error("WifiPreference IpAddress", e.toString());
            return null;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x001e  */
    /* JADX WARN: Removed duplicated region for block: B:23:? A[ADDED_TO_REGION, RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private static java.lang.String getLocalMacAddressFromIp() {
        /*
            r0 = 0
            java.lang.String r1 = getLocalIpAddress()     // Catch: java.net.UnknownHostException -> L12 java.net.SocketException -> L17
            java.net.InetAddress r1 = java.net.InetAddress.getByName(r1)     // Catch: java.net.UnknownHostException -> L12 java.net.SocketException -> L17
            java.net.NetworkInterface r1 = java.net.NetworkInterface.getByInetAddress(r1)     // Catch: java.net.UnknownHostException -> L12 java.net.SocketException -> L17
            byte[] r1 = r1.getHardwareAddress()     // Catch: java.net.UnknownHostException -> L12 java.net.SocketException -> L17
            goto L1c
        L12:
            r1 = move-exception
            r1.printStackTrace()
            goto L1b
        L17:
            r1 = move-exception
            r1.printStackTrace()
        L1b:
            r1 = r0
        L1c:
            if (r1 == 0) goto L56
            int r2 = r1.length
            r3 = 6
            if (r2 == r3) goto L23
            goto L56
        L23:
            int r0 = r1.length
            r2 = 0
            java.lang.String r3 = ""
            r4 = 0
        L28:
            r5 = 1
            if (r4 >= r0) goto L4d
            r6 = r1[r4]
            java.lang.StringBuilder r7 = new java.lang.StringBuilder
            r7.<init>()
            r7.append(r3)
            java.lang.Object[] r3 = new java.lang.Object[r5]
            java.lang.Byte r5 = java.lang.Byte.valueOf(r6)
            r3[r2] = r5
            java.lang.String r5 = "%02x:"
            java.lang.String r3 = java.lang.String.format(r5, r3)
            r7.append(r3)
            java.lang.String r3 = r7.toString()
            int r4 = r4 + 1
            goto L28
        L4d:
            int r0 = r3.length()
            int r0 = r0 - r5
            java.lang.String r0 = r3.substring(r2, r0)
        L56:
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.sangfor.ssl.common.DeviceInfo.getLocalMacAddressFromIp():java.lang.String");
    }
}
